Remain sorted
This crate provides an attribute macro to check at compile time that the variants of an enum or the arms of a match expression are written in sorted order.
[]
= "0.2"
Syntax
Place a #[remain::sorted]
attribute on enums, structs, match-expressions, or
let-statements whose value is a match-expression.
Alternatively, import as use remain::sorted;
and use #[sorted]
as the
attribute.
If an enum variant, struct field, or match arm is inserted out of order,
NetDeviceNew(virtio::NetError),
SpawnVcpu(io::Error),
+ AaaUhOh(Box<dyn StdError>),
}
then the macro produces a compile error.
error: AaaUhOh should sort before BlockSignal
--> tests/stable.rs:49:5
|
49 | AaaUhOh(Box<dyn StdError>),
| ^^^^^^^
Compiler support
The attribute on enums and structs is supported on any rustc version 1.31+.
Rust does not yet have stable support for user-defined attributes within a function body, so the attribute on match-expressions and let-statements requires a nightly compiler and the following two features enabled:
As a stable alternative, this crate provides a function-level attribute called
#[remain::check]
which makes match-expression and let-statement attributes
work on any rustc version 1.31+. Place this attribute on any function containing
#[sorted]
to make them work on a stable compiler.